﻿// Copyright 2009 Mike Geise
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Falcon.Core.SqlServer.Repositories
{
	using System.Collections.Generic;
	using Falcon.Core.Collections;
	using Falcon.Core.Domain;
	using Falcon.Core.Domain.Repositories;
	using Falcon.Core.SqlServer.Repositories.Parameters;
	using Falcon.Core.SqlServer.Repositories.Readers;

	public class UserMessageRepository : SqlRepositoryBase, IUserMessageRepository
	{
		/// <summary>
		/// Gets the user message by the specified specification.
		/// </summary>
		/// <param name="specification">The <see cref="UserMessageSpecification"/>.</param>
		/// <returns></returns>
		public UserMessage GetBy(UserMessageSpecification specification)
		{
			return base.GetBy(Tables.UsersMessages, new UserMessageSpecificationParameter(), new UserMessageSingleReader(), specification);
		}

		/// <summary>
		/// Gets the user message by id.
		/// </summary>
		/// <param name="id">The id.</param>
		/// <returns></returns>
		public UserMessage GetById(int id)
		{
			return base.GetById(Tables.UsersMessages, new UserMessageSingleReader(), id);
		}

		/// <summary>
		/// Gets all the user messages.
		/// </summary>
		/// <returns></returns>
		public IList<UserMessage> GetAll()
		{
			return this.GetPaged(new UserMessageSpecification()).Items;
		}

		/// <summary>
		/// Gets all the user messages.
		/// </summary>
		/// <param name="specification">The <see cref="UserMessageSpecification"/>.</param>
		/// <returns></returns>
		public IPagedList<UserMessage, UserMessageSpecification> GetPaged(UserMessageSpecification specification)
		{
			return base.GetPaged(Tables.UsersMessages, new UserMessageSpecificationParameter(), new UserMessageReader(), specification);
		}

		/// <summary>
		/// Gets the count of user messages using the specified specification.
		/// </summary>
		/// <param name="specification">The specification.</param>
		/// <returns></returns>
		public int Count(UserMessageSpecification specification)
		{
			return base.Count(Tables.UsersMessages, new UserMessageSpecificationParameter(), specification);
		}

		/// <summary>
		/// Inserts the user message into the storage.
		/// </summary>
		/// <param name="message">The <see cref="UserMessage"/>.</param>
		public void Insert(UserMessage message)
		{
			base.Insert(Tables.UsersMessages, new UserMessageParameter(), message);
		}

		/// <summary>
		/// Updates the specified user message in the storage.
		/// </summary>
		/// <param name="message">The <see cref="UserMessage"/>.</param>
		public void Update(UserMessage message)
		{
			base.Update(Tables.UsersMessages, new UserMessageParameter(), message);
		}

		/// <summary>
		/// Deletes the specified user message in the storage.
		/// </summary>
		/// <param name="message">The <see cref="UserMessage"/>.</param>
		public void Delete(UserMessage message)
		{
			base.Delete(Tables.UsersMessages, message);
		}
	}
}